<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="/stylesheets/reg.css">
    <script src="/javascripts/jquery.js"></script>
    <script src="/javascripts/angular.js"></script>
    <!--<script src="../models/public.js"></script>-->
    <!--<script src="/javascripts/controller.js"></script>-->
    <script src="/plugin/bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/plugin/bootstrap/css/bootstrap.css">
</head>
<body>
<main>
    <div class="logo"><a href="/"><img src="/images/logo.png" alt=""></a></div>
    <h2 id="h2">请先登陆</h2>
    <div class="floatright" ng-app="user_Login">
        <div class="regBoard" ng-controller="userLogin">
            <form class="form" name="loginForm" ng-submit="processLoginForm(loginForm.$valid)" novalidate>
                <h2><small class="text-danger hide" id="errorInfo">邮箱格式不正确</small></h2>
                <div class="form-group">
                    <label>邮箱地址</label>
                    <input type="email" class="form-control" name="email" id="email" placeholder="请输入邮箱地址"
                           ng-model="loginFormData.email"
                           ng-pattern="/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/"
                           required/>
                    <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                           class="control-label text-danger"
                           ng-show="loginForm.email.$invalid && !loginForm.email.$pristine"><i
                                class="glyphicon glyphicon-info-sign"></i> 请填写正确的QQ邮箱地址</label>
                    <!--<input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="请输入邮箱">-->
                </div>
                <div class="form-group">
                    <label>密码</label>
                    <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码"
                           ng-pattern="/(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{5,}/" ng-maxlength="12"
                           ng-model="loginFormData.password" required/>
                    <label style="display:inline-block;width: 250px;font-size: 15px;" ng-cloak for="inputError"
                           class="control-label text-danger"
                           ng-show="loginForm.password.$invalid && !loginForm.password.$pristine"><i
                                class="glyphicon glyphicon-info-sign"></i> 6-12位，只能包含字母、数字和下划线</label>
                </div>
                <button role="button" ng-disabled="loginForm.$invalid" class="btn btn-primary" id="button">登陆帐号</button>
                <button style="margin: 30px 0 30px 0" class="btn" id="back">取消登陆</button>
            </form>
        </div>
    </div>
</main>
</body>
</html>
<script>
    var user_Login = angular.module('user_Login',[]);
    user_Login.controller("userLogin",function($scope,$http){
        $scope.processLoginForm = function(isVaild){
            console.log($scope.loginFormData);
            if(isVaild){
                $http({
                    method:'POST',
                    url:'/userLogin',
                    data: $.param($scope.loginFormData),
                    headers:{'Content-Type':'application/x-www-form-urlencoded'}
                }).success(function(data){
                    if (data === "success") {
                        alert('恭喜您,登陆成功');
                        window.location = "/";
                    } else {
                        $('#errorInfo').removeClass('hide').text(data)
                    }
                })
            }
        }
    })

    var back = document.querySelector('#back');
    back.onclick = function () {
        window.history.go(-1);
    }
</script>




